package com.taobao.top.demo.common;

import java.util.List;

import com.taobao.top.demo.dataobject.PropImg;
import com.taobao.top.demo.dataobject.PropValue;
import com.taobao.top.demo.exception.DemoException;
import com.taobao.top.demo.getData.GetItemPropValues;


/**
 * 将颜色属性与其对应的颜色名组合起来
 * @author Jessica
 *
 */
public class ConvertProperties {

	public static void setColorName(List<PropImg> propImgs,String cid) throws DemoException{
		List<PropValue> propValues = GetItemPropValues.getPropValue(cid);
		for(int i = 0;i<propImgs.size();i++){
			PropImg propImg = new PropImg();
			propImg.setCreated(propImgs.get(i).getCreated());
			propImg.setPosition(propImgs.get(i).getPosition());
			propImg.setProperties(propImgs.get(i).getProperties());
			propImg.setPropimgId(propImgs.get(i).getPropimgId());
			propImg.setUrl(propImgs.get(i).getUrl());
			String properties = propImg.getProperties();
			String[] props = propImg.getProperties().split(":");
			String vid = props[1];
			vid = vid.trim();
			for(int j = 0;j < propValues.size();j++){
				PropValue propValue = propValues.get(j);
				if(propValue.getVid().equals(vid)){
					propImg.setName(propValue.getName());
					if(propImgs.get(i).getNameAlias()!= null){
						propImg.setNameAlias(propImgs.get(i).getNameAlias());
					}else{
						propImg.setNameAlias(propValue.getName());
					}
					break;
				}
			}
			propImgs.remove(i);
			propImgs.add(i, propImg);
		}
	}
}
